/****framework_layer.jsp에 정의되어있던 스크립트를 분리함. *****/
////////////////  팝업 레이어 관련 스크립트 시작
var isIE=document.all;
var systemDiv    =  document.getElementById("layerDiv_system");
var emergencyDiv =	document.getElementById("layerDiv_emergency");
var notice0Div   =  document.getElementById("layerDiv_notice0");
var notice1Div   =  document.getElementById("layerDiv_notice1");
var notice2Div   =  document.getElementById("layerDiv_notice2");
var notice3Div   =  document.getElementById("layerDiv_notice3");
var errPopDiv    =  document.getElementById("layerDiv_errPop");

var moveDivID = "";

function layerMove(e){
	if (navigator.appName == "Netscape") {
		offsetx=isIE ? event.pageX : e.pageX;
		offsety=isIE ? event.pageY : e.pageY;

		moveLayerDiv = document.getElementById(this.id);
		moveDivID = this.id;

		nowX=parseInt(moveLayerDiv.style.left);
		nowY=parseInt(moveLayerDiv.style.top);
		oldx = e.pageX-nowX;
		oldy = e.pageY-nowY;
	}else{
		offsetx=isIE ? event.clientX : e.clientX;
		offsety=isIE ? event.clientY : e.clientY;

		moveLayerDiv = document.getElementById(this.id);
		moveDivID = this.id;

		nowX=parseInt(moveLayerDiv.style.left);
		nowY=parseInt(moveLayerDiv.style.top);
		oldx = event.clientX-nowX;
		oldy = event.clientY-nowY;
	}

	MoveEnabled=true;
	document.onmousemove=layerMove2;
}

function layerMove2(e){
	if (!MoveEnabled) return;
	moveLayerDiv = document.getElementById(moveDivID);

	if (navigator.appName == "Netscape") {
		moveLayerDiv.style.left = nowX+e.pageX-offsetx;
		moveLayerDiv.style.top  = nowY+e.pageY-offsety;
	}else{
		moveLayerDiv.style.left = nowX+event.clientX-offsetx;
		moveLayerDiv.style.top  = nowY+event.clientY-offsety;
	}

	document.onmouseup = Function("MoveEnabled=false");
	return false;
}

function mouseMove() {
    try{
        //window.onresize=LayerMove3;
        systemDiv.onmousedown  	 = layerMove;
        emergencyDiv.onmousedown = layerMove;
        notice0Div.onmousedown   = layerMove;
        notice1Div.onmousedown   = layerMove;
        notice2Div.onmousedown   = layerMove;
        notice3Div.onmousedown   = layerMove;
        errPopDiv.onmousedown    = layerMove;
    }catch(e){}
}
//addLoadEvent(mouseMove);
/// 팝업 레이어 관련 스크립트 끝   /////////////

//HTML 코딩을 만들어 리턴한다. (시스템 공지에서 사용)
function makeMsg(title,desc,divObj,setpageLimitDay,index,cookieName) {
	var msg = "<div class='wp_wrap_layer'>" +
					 "<div class='wp_tr_layer'>" +
					"   <div class='wp_tc_layer'>" +
					"      <h1 id='wpHeader1'>"+ title + "<a href='#none' onclick='javascript:document.getElementById(\""+divObj+"\").style.display = \"none\";' ><img src='"+pageContextPath+"/cxw/images/fwk/notice/btn_close.gif' alt='close' /></a></h1>" +
					"    </div>" +
					"</div>" +
					"<div class='wp_mc_layer'>" +
					"   <div id='wpContent' class='wp_content_layer'>" +
					"      <div id='wpPop' class='wp_pop_layer'>" + desc + "</div>" +
					"   </div>";
	if(setpageLimitDay != undefined && setpageLimitDay != null && setpageLimitDay != "null") {
		msg = msg + "   <div id='wpContent' style='overflow:auto;align=right;'>" +
					"      <div id='wpPop' style='padding:30px 10px 0 0;'>" +
					"        <table width=100% ><tr><td align=center> "+
					//"	   	 <input type='checkbox' name='' onclick='javascript:closeStateCheckLayer(\""+cookieName+"\",\""+setpageLimitDay+"\",\""+index+"\");'>"+setpageLimitDay+"일 동안 띄우지 않기"  +
					"	   	 <input type='checkbox' name='' onclick='javascript:closeStateCheckLayer(\""+cookieName+"\",\""+setpageLimitDay+"\",\""+index+"\");'> 하루동안 다시 열지 않기 "  +
					"		 </td></tr></table> " +
					"		</div>" +
					"  </div>";
	}
		msg = msg + "</div>" +
					"<div class='wp_br_layer'>" +
					"    <div class='wp_bl_layer'></div>" +
					"</div>" +
					"</div>";
	return msg;
}

//HTML 코딩을 만들어 리턴한다. (페이지별 공지에서 사용)
function makePageNoticeMsg(title,desc,divObj,setpageLimitDay,index,cookieName) {
	var msg = "<h1 class='x-window-header'>"+ title + "</h1>" +
						"		<div class='x-window-body'>" +
						"		<div class='pop_content dcu_regsystem' style='width:350px;'>" +
						"		  <h2 class='pop_tit3 mar_t15'>아래 내용을 확인하세요.</h2>" +
						"    		<p class='guide_txt mar_t6'>" + desc + "</p>";
	if(setpageLimitDay != undefined && setpageLimitDay != null && setpageLimitDay != "null") {
		msg = msg +  "<p align=right><input type='checkbox' name='' onClick='javascript:closeStateCheckLayer(\""+cookieName+"\",\""+setpageLimitDay+"\",\""+index+"\");'>"+setpageLimitDay+"일 동안 띄우지 않기</p>";
	}
    msg = msg +  "</div></div>";
	return msg;
}

function setCookie( name, value, expiredays ) //쿠키명, 쿠키구분값, 쿠키 유효기간.
{
	//먼저 현재 시간을 얻어온다..
	var todayDate = new Date();
	todayDate.setDate( todayDate.getDate() + (expiredays*1) ); // 오늘 날짜 + expiredays
	document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";"
}

function closeStateCheckLayer(cookieName,validDate, layerCnt)  {
	setCookie(cookieName, "no" , validDate);   // 부모창에서 지정한 쿠키네임과 일치 해야 합니다.
	closeLayer(layerCnt);
}

function closeLayer(layerCnt){
	var layerDiv = eval("document.all.layerDiv_notice"+layerCnt);
	layerDiv.style.display = 'none';
}

